public class myArray {

    private int[] array;
    private int size;

    public myArray(int capacity){
    this.array = new int[capacity];
    size = 0;
    }

/*
* 数组插入
* */
    public void insert(int element,int index) throws Exception{
        if (index < 0 || index > size){
           throw new IndexOutOfBoundsException("超出数组实际范围");
        }
        if (size > array.length){
            resize();
        }
        for (int i = size-1;i>=index;i--){
            array[i+1] = array[i];
        }
        array[index] = element;
        size++;
    }
/*
* 数组输出
* */
    public void outPut(){
        for (int i=0;i<size;i++){
            System.out.println(array[i]);
        }
    }

    public int delete(int index){
        if (index < 0 || index >= size){
            throw  new IndexOutOfBoundsException("超出数组实际范围");
        }
        int deleteElement = array[index];
        for ( int i=index; i<size-1; i++){
            array[i] = array[i+1];
        }
        size--;
        return deleteElement;
    }

    /*
    * 数组扩容
    * */
    public void resize(){
        int[] arrayNew = new int[array.length*2];
        System.arraycopy(array,0,arrayNew,0,array.length);
        array = arrayNew;
    }

    public static void main(String[] args) throws Exception {
        myArray array1 = new myArray(10);
        array1.insert(1,0);
        array1.insert(2,1);
        array1.insert(3,2);
        array1.insert(4,3);
        array1.insert(5,4);
        array1.delete(3);
        array1.delete(2);
        array1.outPut();
    }


}
